#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;

int StrtoInt(char *s){
	return (s[0]-48)*1000+(s[1]-48)*100+(s[2]-48)*10+s[3]-48; 
} 
void InttoStr(char *s,int x){
	int i,cnt,x1=x;
	s[4]='\0';
	for( cnt=0; x1; cnt++ ) x1/=10;
	for( i=3; cnt>0; cnt-- ){
		s[i]=x%10+48; i--;
		x/=10;
	}
	for( ; i>-1; i-- ) s[i]=0+48;
}

int main(){
	char s1[5],s2[5];
	int s,k=-1;
	cin>>s;
	InttoStr(s1,s);
	while( k!=0&&k!=6174 ){
		strcpy(s2,s1);
		sort(s1,s1+4);
		sort(s2,s2+4,greater<char>());
		k=StrtoInt(s2)-StrtoInt(s1);
		cout<<s2<<" - "<<s1<<" = "; printf("%04d\n",k);
		InttoStr(s1,k);
	}
	return 0;
} 
